<?php
//error_reporting(0);
include('../includes/config.php');

require_once('../libs/skyrock.class.php');
$time = time();
$retour = mysql_query('SELECT * FROM ecrire WHERE status="0" AND time <="'.$time.'" ORDER by id DESC');

while ($donnees = mysql_fetch_array($retour)){
	//echo $donnees['username'].'<br />'.$donnees['password'];
	$skyblog = new skyrock($donnees['username'], $donnees['password']);
	$titre = stripslashes($donnees['titre']);
	$contenu = stripslashes($donnees['content']);
	$titre = htmlentities($titre, ENT_QUOTES, mb_detect_encoding($titre)); 
	$contenu = htmlentities($contenu, ENT_QUOTES, mb_detect_encoding($contenu)); 
	$titre = html_entity_decode($titre);
	$contenu = html_entity_decode($contenu);
	$image64 = stripslashes($donnees['image64']);
	$type = $donnees['type'];
	$online = stripslashes($donnees['online']);
	$post = $skyblog->newPost($titre,$contenu, $online);
	$image = $skyblog->newMedia($post,$type,$image64);
	echo 'Article publié : <a href="http://'.substr($donnees['username'], 1).'.skyrock.com/article_'.$post.'.html" target="_blank">'.$titre.'</a> (id : '.$post.')<br />';
	if($image['url'] != '0')
	{
	//echo '<p><strong>Image ajoutée</strong> : <a href="'.$image['url'].'">'.$image['url'].'</a><p>';
	}
	else
	{
	//echo '<strong>Image refusée par Skyrock</strong>';
	}
	$id = $donnees['id'];
	mysql_query('UPDATE ecrire SET status= "1" WHERE id ='.$id);

}